package services

import (
	"errors"
	"github.com/kataras/iris"
	"irisfarm/app/core"
	"irisfarm/app/models"
)

type UserService struct {
}

// 通过用户名获取用户
func (u *UserService) GetByUsername(ctx iris.Context) (models.UsersModel, error) {
	userModel := models.UsersModel{}
	core.DB.Where("username = ?", ctx.PostValue("username")).First(&userModel)

	if userModel.ID == 0 {
		return userModel, errors.New("不存在的用户")
	}
	return userModel, nil
}
